package com.sea.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.sea.wechat.request.po.Button;
import com.sea.wechat.util.ConfigUtil;
import com.sea.wechat.util.HttpUtils;
import com.sea.wechat.util.JedisUtil;
import com.sea.wechat.util.RedisKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**   
 * @ClassName:     MenuController   
 * @Description:   菜单接口   
 * @author:        wl
 * @date:          2017年8月3日 上午11:55:24     
 */  
@RestController
@RequestMapping(value="menu")
public class MenuController {

	private static final Logger logger = LoggerFactory.getLogger(MenuController.class);
	
	@Autowired
	private ConfigUtil configUtil;
	
	@RequestMapping(value="create")
	public String createMenu(@RequestBody Button button){
		logger.info("创建菜单请求参数:"+button);
		if(button!=null){
			String url = configUtil.getCreateMenuUrl()+ JedisUtil.get(RedisKey.ACCESS_TOKEN);
			Map<String, String> head = new HashMap<String, String>();
			head.put("Content-Type", "application/json");
			String result = HttpUtils.HttpsClientPost(url, head, null, JSONObject.toJSONString(button));
			logger.info("返回参数:"+result);
			return null;
		}else {
			return "请求参数不能为空";
		}
	}
	
}
